package com.hspedu.arrays;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author Charlie
 * @version 1.0
 * @date 28/6/2025 下午1:33
 */
public class ArrayTest {
    public static void main(String[] args) {
      int []  arr = {22,33,55,66,100};
      int value = 60;

        int[] arr2 = insertValue(arr, value);

        for (int i : arr2) {
            System.out.println(i);
        }



    }

    public static int[] insertValue(int[]arr,int value){
        int index= 0;
        int[] arr2 = new int[arr.length + 1];


        for (int i = 0; i < arr.length-1; i++) {
            if(value < arr[i+1] &&  value>arr[i]){
                index= i ;
                break;
            }
        }



        for (int i = 0; i <index+1; i++) {
            arr2[i]=arr[i];
        }
            arr2[index+1]=value;
        for (int i = index+1 ; i < arr.length; i++) {
            arr2[i+1]=arr[i];
        }

        return arr2;
    }

}
